package com.qf.util;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @author lyx
 * @date 2022/7/11 10:34
 */
public class ZkUtil {

    /**
     * 获取集群节点操作对象
     * @return
     */
    public static CuratorFramework getCf(){
        //1. 设置连接最大超时时间, 以及超时重试次数
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(3000,2);
        //2. 创建集群节点连接操作对象
        CuratorFramework cf = CuratorFrameworkFactory.builder()
                .connectString("192.168.200.129:2181")
                .retryPolicy(retryPolicy)
                .build();
        //3. 开始连接
        cf.start();
        //4. 返回对象
        return cf;
    }
}
